//#define _CRT_SECURE_NO_WARNINGS
//#include <iostream>
//#include <algorithm>
//using namespace std;
//typedef long long LL;
//const int N = 310;
//int n;
//LL a[N];
//LL solve(LL a, LL b)
//{
//	return (a - b) * (a - b);
//}
//int main()
//{
//	cin >> n;
//	for (int i = 1; i <= n; i++)
//	{
//		cin >> a[i];
//	}
//	sort(a + 1, a + 1 + n);
//	LL sum = 0;
//	int left = 0, right = n;
//	bool flag = true;
//	while (left < right)
//	{
//		sum += solve(a[left], a[right]);
//		if (flag)
//		{
//			left++;
//			flag = false;
//		}
//		else
//		{
//			right--;
//			flag = true;
//		}
//	}
//	cout << sum << endl;
//	return 0;
//}

#include<iostream>
typedef long long LL;
using namespace std;
LL n, m;
const int N = 1e5 + 10;
LL a[N];


bool check(LL x)
{
	LL sum = 0;
	LL cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += a[i];
		if (sum > x)
		{
			sum = a[i];
			cnt++;
		}
	}
	if (cnt + 1 > m) return false;
	else return true;
}
int main()
{
	cin >> n >> m;
	LL left = 0, right = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		left = max(left, a[i]);
		right += a[i];
	}
	while (left < right)
	{
		LL mid = (left + right) / 2;
		if (check(mid))
		{
			right = mid;
		}
		else
		{
			left = mid + 1;
		}
	}
	cout << left << endl;
	return 0;
}